package com.css.bjdt_core.cell.entity;

import java.util.List;

import org.nutz.dao.entity.annotation.Column;
import org.nutz.dao.entity.annotation.Name;
import org.nutz.dao.entity.annotation.Table;

import com.css.bjdt_core.executive.Executor;
import com.css.bjdt_core.executive.entity.Exp;
import com.css.bjdt_core.executive.entity.IType;
import com.css.bjdt_core.report.entity.RptTemplateUnitRela;
import com.css.bjdt_core.report.entity.ViewRptStatCategory;
import com.css.bjdt_core.util.ReportConstant;

import lombok.Data;

@Data
@Table("RPT_CELL")
public class Cell {
	@Name
	@Column("CELL_ID")
	protected String cellId;
	@Column("CELL_NAME")
	protected String cellName;
	// 绝对行号
	@Column("ABS_ROW_NUM")
	protected Integer absRowNum;
	// 绝对列号
	@Column("ABS_COL_NUM")
	protected Integer absColNum;
	// 相对行号
	@Column("REL_ROW_NUM")
	protected Integer relRowNum;
	// 相对列号
	@Column("REL_COL_NUM")
	protected Integer relColNum;
	// 优先级
	@Column("CELL_LEVEL")
	protected Integer cellLevel;
	@Column("TEMPLATE_ID")
	protected String templateId;
	// 单元格类型
	@Column("CELL_TYPE")
	protected String cellType;
	// 预设类型
	@Column("QUOTE_TYPE")
	protected String quoteType;
	// 区域类型(1表内,2表外)
	@Column("AREA_TYPE")
	protected String areaType;
	// 是否需要批注(1不需要,2需要)
	@Column("IS_COMMENT")
	protected String isComment;
	// 是否可写
	protected boolean writeAble;
	// 是否可读
	protected boolean readAble;
	// sql表达式
	@Column("SQL_EXP")
	private String sqlExp;
	@Column("CALC_EXP")
	private String calcExpStr;
	//指标解释
	@Column("SQL_CELL_COMMENT")
	private String sqlCellComment;
	// 计算表达式
	private Exp calcExp = new Exp();
	// 校核表达式
	private List<Exp> validationExps;
	// 原表达式
	private String oldExp;
	// base主句
	private String baseClause;
	// where子句
	private String whereClause;
	// join子句
	private String joinClause;

	@Column("STRATEGY_ID")
	private String strategyId;

	private String strategyClassName;

	private ViewRptStatCategory statCategory;

	private Executor executor;

	private RptTemplateUnitRela rptTemplateUnitRela;

	public Integer getRowNum(String expType) {
		if (IType.TABLE_INNER_CELL.equals(expType)) {
			return absRowNum;
		}
		return relRowNum;
	}

	public Integer getColNum(String expType) {
		if (IType.TABLE_INNER_CELL.equals(expType)) {
			return absColNum;
		}
		return relColNum;
	}

	public String getKey() {
		StringBuilder key = new StringBuilder();
		return key.append("[").append(getRelRowNum()).append(ReportConstant.SPLIT_OPERATOR).append(getRelColNum())
				.append("]").toString();
	}

	public enum CellType {
		// 统计
		stat("1"),
		// 输入
		input("2"),
		// 计算
		calc("3"),
		// 其他
		other("4"),
		// 引用
		quote("5"),
		// 空
		cellNull("7");

		private String key;

		CellType(String key) {
			this.key = key;
		}

		public String getKey() {
			return key;
		}
	}

}
